﻿using Cassandra;
using IDAdmin.Lib.DataLayer;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IDAdmin
{
    public partial class Transfer : System.Web.UI.Page
    {
        //private static LevelWebDB lWebDBVN03 = new LevelWebDB();
        //private static LevelWebDB lWebDBVN04 = new LevelWebDB();
        static List<Thread> threadList=new List<Thread>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                int a = 1;
            }
        }

        protected void buttonTranferFilleCard_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            FilledCardWebDB fcWebDB = new FilledCardWebDB();
            fcWebDB.dateTimeList = dateTimeList;
            fcWebDB.tableName = "FilledCard";
            Thread th = new Thread(new ThreadStart(fcWebDB.transfer_FilledCard));
            threadList.Add(th);
            th.Start();
        }

        protected void ButtonTranferLevelVn03_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            LevelWebDB lWebDBVN03 = new LevelWebDB();
            lWebDBVN03.tableName = "LevelVN03";
            lWebDBVN03.dateTimeList = dateTimeList;
            lWebDBVN03.continueTransfer();
            //lWebDBVN03.work();
            Thread th = new Thread(new ThreadStart(lWebDBVN03.work));
            threadList.Add(th);
            th.Start();
        }


        protected void buttonTranferLevelVN04_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            //lWebDBVN04.transfer_Level_Table("LevelVN04", dateTimeList);
            LevelWebDB lWebDBVN04 = new LevelWebDB();
            lWebDBVN04.tableName = "LevelVN04";
            lWebDBVN04.dateTimeList = dateTimeList;
            lWebDBVN04.continueTransfer();
            //lWebDBVN04.work();
            Thread th = new Thread(new ThreadStart(lWebDBVN04.work));
            threadList.Add(th);
            th.Start();
        }

        protected void buttonStop_Click(object sender, EventArgs e)
        {
            //lWebDBVN03.stopTransfer();
        }

        protected void buttonStopTransferLevelVN04_Click(object sender, EventArgs e)
        {
            //lWebDBVN04.stopTransfer();
        }

        protected void buttonCountNumRowLVVN_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            LevelWebDB lWebDBVN03 = new LevelWebDB();
            lWebDBVN03.tableName = "LevelVN03";
            lWebDBVN03.dateTimeList = dateTimeList;
            lWebDBVN03.countRowNum();
            //lWebDBVN03.tableName = "LevelVN03";
            //lWebDBVN03.dateTimeList = dateTimeList;
            //lWebDBVN03.countRowNum();
        }

        protected void buttonCountGSVN03_Click(object sender, EventArgs e)
        {
            TestWebDB.countGoldShopVN03();
        }

        protected void buttonCountFC_Click(object sender, EventArgs e)
        {

            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            List<FilledCard> list = WebDB.getFilledCardData(dateTimeList);

            //List<FilledCard> result = new List<FilledCard>();
            //List<int> typeList = new List<int> { 0 };
            //try
            //{
            //    using (ISession session = ConnectionHelper.getConnectionForCasGhStats())
            //    {
            //        foreach (int type in typeList)
            //        {
            //            string cmdText = "SELECT filltime,account,point FROM filledcard";
            //            try
            //            {
            //                RowSet rowSet = session.Execute(cmdText);
            //                foreach (Row r in rowSet)
            //                {
            //                    FilledCard fc = new FilledCard();
            //                    fc.FILLTIMESTR = r.GetValue<DateTime>("filltime").ToString("dd/MM/yyyy");
            //                    fc.FILLTIME = DateTime.ParseExact(fc.FILLTIMESTR, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            //                    fc.ORIGIONFILLTIME = r.GetValue<DateTime>("filltime").ToLocalTime();
            //                    fc.POINT = r["point"].ToString();
            //                    fc.ACCOUNT = r["account"].ToString();
            //                    result.Add(fc);
            //                }
            //            }
            //            catch (Exception ex)
            //            {
            //            }
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}
        }

        protected void ButtonStopAllTranfser_Click(object sender, EventArgs e)
        {
            foreach (Thread th in threadList)
            {
                try
                {
                    th.Abort();
                }
                catch (Exception ex)
                {

                }
            }
        }

        protected void buttonTranferLevelVN05_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            //lWebDBVN04.transfer_Level_Table("LevelVN04", dateTimeList);
            LevelWebDB lWebDBVN05 = new LevelWebDB();
            lWebDBVN05.tableName = "LevelVN05";
            lWebDBVN05.dateTimeList = dateTimeList;
            lWebDBVN05.continueTransfer();
            //lWebDBVN04.work();
            Thread th = new Thread(new ThreadStart(lWebDBVN05.work));
            threadList.Add(th);
            th.Start();
        }

        protected void buttonTranferLevelVN08_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            //lWebDBVN04.transfer_Level_Table("LevelVN04", dateTimeList);
            LevelWebDB lWebDBVN08 = new LevelWebDB();
            lWebDBVN08.tableName = "LevelVN08";
            lWebDBVN08.dateTimeList = dateTimeList;
            lWebDBVN08.continueTransfer();
            //lWebDBVN04.work();
            Thread th = new Thread(new ThreadStart(lWebDBVN08.work));
            threadList.Add(th);
            th.Start();
        }

        protected void buttonTranferLevelVN09_Click(object sender, EventArgs e)
        {
            DateTime dtFormDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.beginDateTextBox.Text);
            DateTime dtToDate = IDAdmin.Common.ConverterWorkData.convertStringToDateTime(CountToolBar.toDateTextBox.Text);
            List<DateTime> dateTimeList = IDAdmin.Common.ConverterWorkData.getDateListBetween(dtFormDate, dtToDate);
            //lWebDBVN04.transfer_Level_Table("LevelVN04", dateTimeList);
            LevelWebDB lWebDBVN09 = new LevelWebDB();
            lWebDBVN09.tableName = "LevelVN09";
            lWebDBVN09.dateTimeList = dateTimeList;
            lWebDBVN09.continueTransfer();
            //lWebDBVN04.work();
            Thread th = new Thread(new ThreadStart(lWebDBVN09.work));
            threadList.Add(th);
            th.Start();
        }
    }
}